local skel = fk.CreateSkill{--定义
  name = "knu__zhaoxin",
}

local DIY = require "packages/diy_utility/diy_utility"

Fk:loadTranslationTable{--翻译
  ["knu__zhaoxin"] = "昭心",
  [":knu__zhaoxin"] = "出牌阶段，你可以明置任意张手牌（需大于此阶段上次明置的牌数），"..
  "令你使用的下一张牌无距离和次数限制；然后若你的手牌均明置，则你依次将每种花色的所有手牌当【无中生有】使用。",
  ["#knu__zhaoxin"] = "昭心：你可以明置至少 %arg 张手牌，令你使用的下一张牌无距离和次数限制",

  ["@@knu__zhaoxin"] = "昭心",

  ["$knu__zhaoxin1"] = "孤欲身登大宝，射鹿九州，问鼎天下！",
  ["$knu__zhaoxin2"] = "天时有常，汉终魏继，魏终则司马氏当继。",
}

skel:addEffect("active",{
  prompt = function (self, player)
    return "#knu__zhaoxin:::"..player:getMark("knu__zhaoxin-phase") + 1
  end,
  can_use = function (self, player)
    return #player:getCardIds("h") - #DIY.getShownCards(player) > player:getMark("knu__zhaoxin-phase")
  end,
  min_card_num = function (self, player)
    return player:getMark("knu__zhaoxin-phase") + 1
  end,
  card_filter = function (self, player, to_select, selected, selected_targets)
    local cards_show = DIY.getShownCards(player)
    return not table.contains(DIY.getShownCards(player),to_select)
  end,
  target_num = 0,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    local cards = effect.cards
    room:setPlayerMark(player,"knu__zhaoxin-phase",#cards)
    room:setPlayerMark(player,"@@knu__zhaoxin",#cards)
    DIY.showCards(player,cards)
    --若均明置
    if not (#player:getCardIds("h") == #DIY.getShownCards(player)) then
      return
    end
    -- Fk:getCardById(card):getSuitString(true)
    local list = {"log_spade", "log_heart", "log_club", "log_diamond"}
    while #list > 0 do
      local choice
      if #list > 1 then
        choice = room:askToChoice(player, {
          choices = list,
          skill_name = skel.name,
        })
      else
        choice = list[1]
      end
      table.removeOne(list,choice)
      local cids = table.filter(player:getCardIds("h"),function (cid)
        return Fk:getCardById(cid):getSuitString(true) == choice
      end)
      if #cids > 0 then
        room:useVirtualCard("ex_nihilo", cids, player, player, skel.name)
      end
    end
  end,
})

--用牌无距离和次数限制
skel:addEffect("targetmod", {
  bypass_times = function(self, player, skill, scope, card)
    if player:getMark("@@knu__zhaoxin") then
      return true
    end
  end,
  bypass_distances = function(self, player, skill, scope, card)
    if player:getMark("@@knu__zhaoxin") then
      return true
    end
  end,
})
skel:addEffect(fk.CardUsing, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@knu__zhaoxin")
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player,"@@knu__zhaoxin",0)
  end,
})


return skel